---
title: "Exploratory Analysis of Daily EMA Data"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
source: embed
---
```{r setup, include=FALSE}
# Setup options
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
# CRAN packages
library(flexdashboard)
library(dplyr)
library(knitr)
library(ggplot2)
# devtools::install_github("mbcann01/dataclean")
library(dataclean)
# Load ea_kable
source("/Users/bradcannell/Dropbox/Research/mChat/R scripts/ea_kable.R")
# Load data
load("/Users/bradcannell/Dropbox/Research/mChat/data/daily_april_2016.RData")
# Sort by case number and date
daily <- dplyr::arrange(daily, case_number, date)
```
Overview {.sidebar}
===============================================================================
Here we plot the aggregate unconditional distribution of responses for each of the following variables:
1. Feelings at time of assessment
2. Location at time of assessment
3. Activity at time of assessment
4. Physical activity yesterday
5. Diet yesterday
6. Medication use yesterday
7. Freetime activities yesterday
8. Meaningful Interaction yesterday
9. Substance use yesterday
Feeling
===============================================================================
Feelings Table
-------------------------------------------------------------------------------
### Feelings at time of assessment
```{r feeling_table}
feelings <- select(daily, happy, frustrated, sad, worried, restless, excited, calm, lonely, bored, sluggish)
vars <- tools::toTitleCase(names(feelings))
ea_kable(
x = feelings,
xlab = vars,
nrows = 10,
ncols = 6,
colnames = c("Feeling", "Strongly Disagree", "Disagree", "Neutral", "Agree",
"Strongly Agree")
)
```
Feelings Charts
-------------------------------------------------------------------------------
```{r plot_emotions}
for (var in vars) {
plot <- ggplot(daily, aes_string(x = tolower(var))) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("I Feel", var, "Right Now")) +
theme_bw()
print(plot)
}
```
Location
===============================================================================
Location Table
-------------------------------------------------------------------------------
### Location at time of assessment
```{r location_table}
x <- select(daily, bus_loc, church_loc, home_loc, frifam_loc, store_loc, outdoors_loc, other_loc, restaurant_loc, school_loc, work_loc)
loc <- c("Bus, Train, or Vehicle", "Church", "Home", "Friend's or Relative's House", "Store / Mall", "Outdoors", "Other", "Restaurant", "School / Library", "Work")
ea_kable(
x = x,
xlab = loc,
nrows = 10,
ncols = 3,
colnames = c("Location", "No", "Yes")
)
```
Location Charts
-------------------------------------------------------------------------------
```{r plot_location}
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("Location at Time of Assessment:", loc[i])) +
theme_bw()
print(plot)
i <- i + 1
}
```
Activity
===============================================================================
Activity Table
-------------------------------------------------------------------------------
### Activity at time of assessment
```{r activity_table}
x <- select(daily, pre_who, sit_act, sleep_act, stand_act, talk_act, walk_act, other_act)
act <- c("Interacting With Someone", "Sitting", "Sleeping", "Standing", "Talking", "Walking / Excercising", "Other")
ea_kable(
x = x,
xlab = act,
nrows = 7,
ncols = 3,
colnames = c("Activity", "No", "Yes")
)
```
Activity Charts
-------------------------------------------------------------------------------
```{r plot_act}
# Plot all of these on a single column chart
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste(act[i], "Right Before the Phone Rang")) +
theme_bw()
print(plot)
i <- i + 1
}
```
Physical Activity
===============================================================================
Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------
### Physical activity yesterday (Yes / No)
```{r physact_table_1}
x <- select(daily, bike_yest, run_yest, cleaning_yest, none_yest, pedometer)
act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer")
ea_kable(
x = x,
xlab = act,
nrows = 5,
ncols = 3,
colnames = c("Activity", "No", "Yes")
)
```
### Physical activity yesterday (Minutes)
```{r physact_table_2}
x <- select(daily, min_walk, min_run, min_act)
act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home")
ea_kable(
x = x,
xlab = act,
nrows = 3,
ncols = 7,
colnames = c("Activity", "10 Minutes or Less", "11-20 Minutes", "21-30 Minutes",
"31-40 Minutes", "41-50 Minutes", "More than 50 Minutes")
)
```
### Sitting time yesterday
```{r sitting_table}
x <- select(daily, min_sit)
ea_kable(
x = x,
xlab = "Sitting Time Yesterday",
nrows = 1,
ncols = 7,
colnames = c("Variable", "4 or Fewer Hours", "More than 4 Hours- 6 Hours",
"More than 6 Hours- 8 Hours", "More than 8 Hours- 10 Hours",
"More than 10 Hours - 12 Hours", "More than 12 Hours")
)
```
Physical Activity Charts
-------------------------------------------------------------------------------
```{r plot_act_yest}
x <- names(select(daily, bike_yest, run_yest, cleaning_yest, none_yest, pedometer, min_walk, min_run, min_act, min_sit))
act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer", "Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Sat")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste(act[i], "Yesterday")) +
theme_bw() +
if (i > 5) {
theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
} else {
theme()
}
print(plot)
i <- i + 1
}
# Plot steps
ggplot(daily, aes(x = steps)) +
geom_histogram(binwidth = 1000) +
scale_x_continuous("") +
ggtitle("Steps Yesterday") +
theme_bw()
```
Diet
===============================================================================
Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------
### Ate any yesterday (Yes / No)
```{r diet_table_1}
x <- select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat)
food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")
ea_kable(
x = x,
xlab = food,
nrows = 5,
ncols = 3,
colnames = c("Food", "No", "Yes")
)
```
### Servings ate yesterday
```{r diet_table_2}
x <- select(daily, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat)
food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")
ea_kable(
x = x,
xlab = food,
nrows = 5,
ncols = 7,
colnames = c("Food", "0 Servings", "1 Serving", "2 Servings", "3 Servings", "4 Servings",
"5 or More Servings")
)
```
Diet Charts
-------------------------------------------------------------------------------
```{r diet_yest}
x <- names(select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat))
food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat", "Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("Ate", food[i], "Yesterday")) +
theme_bw()
print(plot)
i <- i + 1
}
```
Medication
===============================================================================
Medication Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------
### Did you take all your medication as prescribed yesterday, and if not, which ones didn't you take?
```{r med_table_1}
x <- select(daily, take_meds, medtype_dep, medtype_psy, medtype_ast, medtype_bp, medtype_diab, medtype_pain, medtype_chol, medtype_anti, medtype_other)
xlab <- c("Take Medications", "Didn't Take Depression / Anxiety / Mood Medication", "Didn't Take Psychiatric Medication", "Didn't Take Asthma / COPD Medication", "Didn't Take Blood Pressure Medication", "Didn't Take Diabetes Medication", "Didn't Take Pain Medication", "Didn't Take Cholesterol Medication", "Didn't Take Antibiotic / Antiviral Medication", "Didn't Take Other Medication")
ea_kable(
x = x,
xlab = xlab,
nrows = 10,
ncols = 3,
colnames = c("Medication", "No", "Yes")
)
```
### Why didn't you take medications?
```{r med_table_2}
x <- select(daily, meds_ran_out, meds_forgot, meds_no_need, meds_side, meds_lost, meds_other)
xlab <- c("Ran out", "Forgot", "Don't Need It", "Side Effects", "Got Lost / Stolen", "Other")
ea_kable(
x = x,
xlab = xlab,
nrows = 6,
ncols = 3,
colnames = c("Reason", "Wasn't a Reason", "Was a Reason")
)
```
Medication Charts
-------------------------------------------------------------------------------
```{r med_chart}
# Take (Yes / No)
# Would be much more informative if each were a single column on the same chart
x <- select(daily, take_meds, medtype_dep, medtype_psy, medtype_ast, medtype_bp, medtype_diab, medtype_pain, medtype_chol, medtype_anti, medtype_other)
xlab <- c("Take Medications", "Didn't Take Depression / Anxiety / Mood Medication", "Didn't Take Psychiatric Medication", "Didn't Take Asthma / COPD Medication", "Didn't Take Blood Pressure Medication", "Didn't Take Diabetes Medication", "Didn't Take Pain Medication", "Didn't Take Cholesterol Medication", "Didn't Take Antibiotic / Antiviral Medication", "Didn't Take Other Medication")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste(xlab[i], "Yesterday")) +
theme_bw()
print(plot)
i <- i + 1
}
# Why not?
# Would be much more informative if each were a single column on the same chart
x <- select(daily, meds_ran_out, meds_forgot, meds_no_need, meds_side, meds_lost, meds_other)
xlab <- c("Ran out", "Forgot", "Don't Need It", "Side Effects", "Got Lost / Stolen", "Other")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("Didn't take because:", xlab[i])) +
theme_bw()
print(plot)
i <- i + 1
}
```
Freetime
===============================================================================
Freetime Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------
### How much free time did you have yesterday?
```{r freetime_table_1}
x <- select(daily, free_time)
xlab <- c("Amount")
ea_kable(
x = x,
xlab = xlab,
nrows = 1,
ncols = 7,
colnames = c("Free time", "2 or fewer hours", "More than 2 hours- 4 hours",
"More than 4 hours- 6 hours", "More than 6 hours- 8 hours", "More than 8 hours- 10 hours",
"More than 10 hours")
)
```
### What did you do in your free time yesterday?
```{r freetime_table_2}
x <- select(daily, tv_free, games_free, movie_free, internet_free, book_free, music_free, craft_free, cleaned_free, pets_free, pray_free, sport_free, walk_free, cards_free, shop_free, volunteer_free, social_free, none_free)
xlab <- c("Watched TV", "Played Computer Games", "Went to a Movie", "Surfed the Internet", "Read", "Listened to Music or Played Instrument", "Arts and Crafts", "Cleaned", "Took Care of Pets", "Prayed, Meditated, or Went to Religious Service", "Played a Sport", "Walk or Jog", "Played Cards, Dice, or Board Games", "Went Shopping", "Volunteered", "Socialized", "None of These")
ea_kable(
x = x,
xlab = xlab,
nrows = 17,
ncols = 3,
colnames = c("Activity", "Didn't Do Yesterday", "Did Yesterday")
)
```
Freetime Charts
-------------------------------------------------------------------------------
```{r freetime_chart}
# How much
x <- select(daily, free_time)
xlab <- c("Amount")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle("Amount of Free Time Yesterday") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
print(plot)
i <- i + 1
}
# What they did
# Would be much more informative if each were a single column on the same chart
x <- select(daily, tv_free, games_free, movie_free, internet_free, book_free, music_free, craft_free, cleaned_free, pets_free, pray_free, sport_free, walk_free, cards_free, shop_free, volunteer_free, social_free, none_free)
xlab <- c("Watched TV", "Played Computer Games", "Went to a Movie", "Surfed the Internet", "Read", "Listened to Music or Played Instrument", "Arts and Crafts", "Cleaned", "Took Care of Pets", "Prayed, Meditated, or Went to Religious Service", "Played a Sport", "Walk or Jog", "Played Cards, Dice, or Board Games", "Went Shopping", "Volunteered", "Socialized", "None of These")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("Did in Free Time Yesterday:", xlab[i])) +
theme_bw()
print(plot)
i <- i + 1
}
```
Interaction
===============================================================================
Interaction Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------
### Any meaningful interaction yesterday
```{r interaction_table_1}
x <- select(daily, any_talk, any_group)
xlab <- c("One-On-One Conversations", "Group Interactions")
ea_kable(
x = x,
xlab = xlab,
nrows = 2,
ncols = 3,
colnames = c("Type", "No", "Yes")
)
```
### Amount of meaningful interaction yesterday
```{r interaction_table_2}
x <- select(daily, min_talk, min_group)
xlab <- c("One-On-One Conversations", "Group Interactions")
ea_kable(
x = x,
xlab = xlab,
nrows = 2,
ncols = 8,
colnames = c("Type", "15 or Fewer Minutes", "16-30 Minutes", "31 min- 1 Hour",
"More than 1 Hour- 2 Hours", "More than 2 Hours- 3 Hours", "More than 3 Hours- 4 Hours",
"More than 4 Hours")
)
```
Interaction Charts
-------------------------------------------------------------------------------
```{r interaction_chart}
# Any interaction
x <- select(daily, any_talk, any_group)
xlab <- c("One-On-One Conversations", "Group Interactions")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste(xlab[i], "Yesterday")) +
theme_bw()
print(plot)
i <- i + 1
}
# Amount of interaction
x <- select(daily, min_talk, min_group)
xlab <- c("One-On-One Conversations", "Group Interactions")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("Amount of", xlab[i], "Yesterday")) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
print(plot)
i <- i + 1
}
```
Substances
===============================================================================
Substances Tables
-------------------------------------------------------------------------------
### Substances used yesterday
```{r substance_table}
x <- select(daily, alc_sub, heavy_drink, cig_sub, mar_sub, opi_sub, stim_sub, herb_sub, other_sub, none_sub)
xlab <- c("Alcohol", "5 or More Alcoholic Drinks", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs / Incense", "Another drug", "None")
ea_kable(
x = x,
xlab = xlab,
nrows = 9,
ncols = 3,
colnames = c("Type", "No", "Yes")
)
```
Substances Charts
-------------------------------------------------------------------------------
```{r substance_chart}
x <- names(select(daily, alc_sub, cig_sub, mar_sub, opi_sub, stim_sub, herb_sub, other_sub, none_sub))
sub <- c("Alcohol", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs", "Another drug", "No Substances")
i <- 1
for (var in x) {
plot <- ggplot(daily, aes_string(x = var)) +
geom_bar() +
scale_x_discrete("") +
ggtitle(paste("Participant used", sub[i], "Yesterday")) +
theme_bw()
print(plot)
i <- i + 1
}
```
Session Info
===============================================================================
```{r session_info, echo=FALSE}
sessionInfo()
```